#pragma once
typedef unsigned short Data, Color, Length;
const Color NC = -1;
typedef struct {
    unsigned short X;
    unsigned short Y;
}Coord;
inline bool included(Coord pos, Coord lt, Coord size)
{
    return pos.X >= lt.X && pos.X < lt.X + size.X && pos.Y >= lt.Y && pos.Y < lt.Y + size.Y;
}
inline Coord operator+(const Coord& a, const Coord& b)
{
    return { (unsigned short)(a.X + b.X), (unsigned short)(a.Y + b.Y) };
}
inline Coord operator-(const Coord& a, const Coord& b)
{
    return { (unsigned short)(a.X - b.X), (unsigned short)(a.Y - b.Y) };
}
enum class Relation { relative, fixed };
typedef struct {
    Color _BgC;
    Color _BgR;
    Color _BgG;
    Color _BgB;
    Color _FgC;
    Color _FgR;
    Color _FgG;
    Color _FgB;
    bool bold;
    bool udl;
}Format;
typedef struct {
    char ch;
    Format format;
}Pixel;
inline bool operator==(const Format& a, const Format& b)
{
    return a._BgC == b._BgC && a._BgR == b._BgR && a._BgG == b._BgG && a._BgB == b._BgB && a._FgC == b._FgC && a._FgR == b._FgR && a._FgG == b._FgG && a._FgB == b._FgB && a.bold == b.bold && a.udl == b.udl;
}
inline bool operator!=(const Format& a, const Format& b)
{
    return a._BgC != b._BgC || a._BgR != b._BgR || a._BgG != b._BgG || a._BgB != b._BgB || a._FgC != b._FgC || a._FgR != b._FgR || a._FgG != b._FgG || a._FgB != b._FgB || a.bold != b.bold || a.udl != b.udl;
}
inline bool operator==(const Pixel& a, const Pixel& b)
{
    return a.ch == b.ch && a.format == b.format;
}
inline bool operator!=(const Pixel& a, const Pixel& b)
{
    return a.ch != b.ch || a.format != b.format;
}
#define dempty 0
#define dn1 1
#define dn2 2
#define dn3 3
#define dn4 4
#define dn5 5
#define dn6 6
#define dn7 7
#define dn8 8
#define dn9 9
#define dn10 10
#define dn11 11
#define dn12 12
#define dn13 13
#define dn14 14
#define dn15 15
#define dn16 16
#define dn17 17
#define dn18 18
#define dn19 19
#define dn20 20
#define dn21 21
#define dn22 22
#define dn23 23
#define dn24 24
#define dn25 25
#define dn26 26
#define dn27 27
#define dn28 28
#define dn29 29
#define dn30 30
#define dn31 31
#define dn32 32
#define dn33 33
#define dn34 34
#define dn35 35
#define dn36 36
#define dn37 37
#define dn38 38
#define dn39 39
#define dn40 40
#define dn41 41
#define dn42 42
#define dn43 43
#define dn44 44
#define dn45 45
#define dn46 46
#define dn47 47
#define dn48 48
#define dn49 49
#define dn50 50
#define dn51 51
#define dn52 52
#define dn53 53
#define dn54 54
#define dn55 55
#define dn56 56
#define dn57 57
#define dn58 58
#define dn59 59
#define dn60 60
#define dn61 61
#define dn62 62
#define dn63 63
#define dn64 64
#define dn65 65
#define dn66 66
#define dn67 67
#define dn68 68
#define dn69 69
#define dn70 70
#define dn71 71
#define dn72 72
#define dn73 73
#define dn74 74
#define dn75 75
#define dn76 76
#define dn77 77
#define dn78 78
#define dn79 79
#define dn80 80
#define dn81 81
#define dn82 82
#define dn83 83
#define dn84 84
#define dn85 85
#define dn86 86
#define dn87 87
#define dn88 88
#define dn89 89
#define dn90 90
#define dn91 91
#define dn92 92
#define dn93 93
#define dn94 94
#define dn95 95
#define dn96 96
#define dn97 97
#define dn98 98
#define dn99 99
#define d0 100
#define d1 101
#define d2 102
#define d3 103
#define d4 104
#define d5 105
#define d6 106
#define d7 107
#define d8 108
#define d9 109
#define d10 110
#define d11 111
#define d12 112
#define d13 113
#define d14 114
#define d15 115
#define d16 116
#define d17 117
#define d18 118
#define d19 119
#define d20 120
#define d21 121
#define d22 122
#define d23 123
#define d24 124
#define d25 125
#define d26 126
#define d27 127
#define d28 128
#define d29 129
#define d30 130
#define d31 131
#define d32 132
#define d33 133
#define d34 134
#define d35 135
#define d36 136
#define d37 137
#define d38 138
#define d39 139
#define d40 140
#define d41 141
#define d42 142
#define d43 143
#define d44 144
#define d45 145
#define d46 146
#define d47 147
#define d48 148
#define d49 149
#define d50 150
#define d51 151
#define d52 152
#define d53 153
#define d54 154
#define d55 155
#define d56 156
#define d57 157
#define d58 158
#define d59 159
#define d60 160
#define d61 161
#define d62 162
#define d63 163
#define d64 164
#define d65 165
#define d66 166
#define d67 167
#define d68 168
#define d69 169
#define d70 170
#define d71 171
#define d72 172
#define d73 173
#define d74 174
#define d75 175
#define d76 176
#define d77 177
#define d78 178
#define d79 179
#define d80 180
#define d81 181
#define d82 182
#define d83 183
#define d84 184
#define d85 185
#define d86 186
#define d87 187
#define d88 188
#define d89 189
#define d90 190
#define d91 191
#define d92 192
#define d93 193
#define d94 194
#define d95 195
#define d96 196
#define d97 197
#define d98 198
#define d99 199
#define dA 201
#define dB 202
#define dC 203
#define dD 204
#define dE 205
#define dF 206
#define dG 207
#define dH 208
#define dI 209
#define dJ 210
#define dK 211
#define dL 212
#define dM 213
#define dN 214
#define dO 215
#define dP 216
#define dQ 217
#define dR 218
#define dS 219
#define dT 220
#define dU 221
#define dV 222
#define dW 223
#define dX 224
#define dY 225
#define dZ 226


inline bool DataEmpty(Data dat)
{
    return dat == dempty;
}

inline bool DataPositive(Data dat)
{
    return dat >= d0 && dat <= d99;
}

inline bool DataNegative(Data dat)
{
    return dat >= dn1 && dat <= dn99;
}

inline bool DataZero(Data dat)
{
    return dat == d0;
}

inline bool DataAlpha(Data dat)
{
    return dat >= dA && dat <= dZ;
}

inline int hextoi(char c)
{
    int decimal = 0;
    if (c >= '0' && c <= '9') {
        decimal = decimal * 16 + (c - '0');
    }
    else if (c >= 'A' && c <= 'F') {
        decimal = decimal * 16 + (c - 'A' + 10);
    }
    else if (c >= 'a' && c <= 'f') {
        decimal = decimal * 16 + (c - 'a' + 10);
    }
    return decimal;
}